home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0230_Reversing ShortStrings Revisited.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  847 b   |  42 lines

  1. {
  2. In answer to a fellow subscriber's request, I recently posted to this list a
  3. Delphi Assembler procedure to reverse ShortStrings. After someone pointed out
  4. to me in a private message that my routine was slower than his all-Pascal
  5. alternative, I tried again, and managed to come up with an asm procedure that
  6. actually has a (modest) speed advantage. It is presented below, in case
  7. anyone else can use it.
  8.  
  9. --Paul Sobolik
  10. }
  11. procedure RevString3(var s: ShortString); assembler;
  12. asm
  13.   push esi
  14.   push edi
  15.  
  16.   mov esi,eax
  17.   mov edi,eax
  18.   xor eax,eax
  19.   lodsb
  20.   add edi,eax
  21.   dec edi
  22.   add eax,2
  23.   shr eax,2
  24.   mov ecx,eax
  25.   jecxz @@done
  26. @@loop:
  27.   mov ax,[esi]
  28.   mov dx,[edi]
  29.   xchg al,ah
  30.   mov [edi],ax
  31.   sub edi,2
  32.   xchg dl,dh
  33.   mov [esi],dx
  34.   add esi,2
  35.   dec ecx
  36.   jnz @@loop
  37. @@done:
  38.   pop edi
  39.   pop esi
  40. end;
  41.  
  42.